package com.flower.controller;

import com.flower.pojo.Order;
import com.flower.pojo.User;
import com.flower.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;
    @RequestMapping("/addOrder")
    public Map<String,Object> addOrder(@RequestBody Order order, HttpSession session){
            Map<String,Object> map = new HashMap<>();
            int uid =1;
            try {
                uid=((User)session.getAttribute("user")).getUid();
            }catch (Exception e){

            }
            order.setUid(uid);
            int result = orderService.addOrder(order);
            if(result!=-1){
                map.put("code",200);
                map.put("msg","支付成功");
            }else {
                map.put("code",201);
                map.put("msg","支付失败");
            }
            return map;
    }
}
